﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.HomeServer.Controls;
using Umbrella.Net.Contracts;
using Umbrella.Whs.SharePoint;
using Umbrella.Whs.WhsAddin.Controls;
using System.IO;

namespace Umbrella.Whs.WhsAddin.Wizards.SharePointInstallation
{
    internal class SharePointInstallationWizard : Wizard
    {
        private readonly log4net.ILog _log = log4net.LogManager.GetLogger(typeof(SharePointInstallationWizard));
        private InstallationManager _instMgr = new InstallationManager();

        public IList<SharePointInstallationFile> InstallationFiles
        {
            get; 
            set;
        }

        public IList<SharePointInstallationFile> SelectedInstallationFiles
        {
            get;
            set;
        }

        public IList<SharePointLanguage> Languages
        {
            get;
            set;
        }

        public DirectoryInfo InstallationTempDir
        {
            get
            {
                return new DirectoryInfo(InstallationManager.InstallationTempDir);
            }
        }

        public void CleanupInstallationTempDir()
        {
            _instMgr.CleanupInstallationTempDir();
        }

        public string GetTitleForInstallationPackage(SharePointInstallationFile ip)
        {
            if (this.Languages == null)
                throw new InvalidOperationException("no languages loaded");

            return (
                from l in this.Languages
                where l.LCID == ip.LanguageLCID
                select l.Title
                ).First();
        }

        public SharePointInstallationWizard()
        {
            this.Text = Resources.txtWizardTitle;
            this.Width = CommonSettings.BigWizardStdWidth;
            this.Height = CommonSettings.BigWizardStdHeight;
            this.WizardIcon = Whs.Properties.Resources.icoLogo;

            Init();

            SetTypes(new[]
            {
                typeof(WizardPageHost<Step10_Prepare>),
                typeof(WizardPageHost<Step20_SelectLanguagePacks>),
                typeof(WizardPageHost<Step30_Download>),
                typeof(WizardPageHost<Step40_Install>),
            });
        }
    }
}
